package com.menghao.cloud.service.consumer;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import feign.Feign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * <p>服务-2.<br>
 *
 * @author MarvelCode.
 */
@SpringBootApplication
@RestController
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrix
public class CloudConsumer {

    public static void main(String[] args) {
        SpringApplication.run(CloudConsumer.class, args);
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Autowired
    private HelloService helloService;
    @Autowired
    private HelloServiceImpl helloServiceImpl;

    @GetMapping("hello1")
    public String hello1() {
        return helloServiceImpl.hello();
    }


    @GetMapping("hello2")
    public String hello2() {
        return helloService.sayHello();
    }

    @Value("${marvel.name}")
    private String marvelName;

    @GetMapping("config")
    public String config() {
        return marvelName;
    }
}
